package com.alpha.eceasy.mall.api.constant;

import com.alpha.eceasy.exception.BizException;
import com.baomidou.mybatisplus.annotation.EnumValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Optional;

/**
 * 快递状态枚举
 */
@Getter
@AllArgsConstructor
public enum LogisticsOrderStateEnum {
	/**
	 * 在途
	 */
	IN_TRANSIT(0),
	/**
	 * 揽收
	 */
	THE_GOODS(1),
	/**
	 * 疑难
	 */
	DIFFICULT(2),
	/**
	 * 签收
	 */
	SIGN_IN(3),
	/**
	 * 退签
	 */
	BACK_TO_SIGN(4),
	/**
	 * 派件
	 */
	TO_SEND(5),
	/**
	 * 退回
	 */
	SEND_BACK(6),
	/**
	 * 转投
	 */
	SWITCH_TO(7),
	/**
	 * 待清关
	 */
	WAIT_CUSTOMS_CLEARANCE(10),
	/**
	 * 清关中
	 */
	START_CUSTOMS_CLEARANCE(11),
	/**
	 * 已清关
	 */
	END_CUSTOMS_CLEARANCE(12),
	/**
	 * 清关异常
	 */
	ERROR_CUSTOMS_CLEARANCE(13),
	/**
	 * 拒签
	 */
	VISA_REJECTED(14);

	@EnumValue
	private final Integer code;

	public static LogisticsOrderStateEnum valueFromCode(Integer code){
		Optional<LogisticsOrderStateEnum> first = Arrays.stream(values()).filter(item -> item.getCode().equals(code)).findFirst();
		return first.orElseThrow(BizException::new);
	}
}
